import 'dart:core';

import 'package:flutter/material.dart';
import 'view.dart';
import 'right_dialog.dart';

class DDialogUtils {
  static Color ddMainColor=Color(0xff6D38EF);
  static showRightDialog(BuildContext context, Widget widget) {
    showGeneralDialog(
        context: context,
        barrierDismissible: false,
        transitionDuration: Duration(milliseconds: 600),
        transitionBuilder: (ctx, a, b, w) {
          return w;
        },
        pageBuilder: (BuildContext context, Animation<double> parenAnimation,
            Animation<double> secondaryAnimation) {
          return RightDialog(parenAnimation, widget);
        });
  }

  static showAlphaDialog(BuildContext context, Widget widget) {
    return showGeneralDialog(
        context: context,
        barrierDismissible: false,
        barrierLabel: "",
        barrierColor: Colors.transparent,
        transitionDuration: Duration(milliseconds: 600),
        transitionBuilder: (ctx, a, b, w) {
          return w;
        },
        pageBuilder: (BuildContext context, Animation<double> parenAnimation,
            Animation<double> secondaryAnimation) {
          return AlphaDialog(parenAnimation, widget);
        });
  }

  static Future showBottomDialog(BuildContext context, Widget widget) {
    return showGeneralDialog(
        context: context,
        barrierDismissible: false,
        transitionDuration: Duration(milliseconds: 600),
        transitionBuilder: (ctx, a, b, w) {
          return w;
        },
        pageBuilder: (BuildContext context, Animation<double> parenAnimation,
            Animation<double> secondaryAnimation) {
          return BottomDialog(parenAnimation, widget);
        });
  }

  static showLeftDialog(BuildContext context, Widget widget) {
    showGeneralDialog(
        context: context,
        barrierDismissible: false,
        transitionDuration: Duration(milliseconds: 600),
        transitionBuilder: (ctx, a, b, w) {
          return w;
        },
        pageBuilder: (BuildContext context, Animation<double> parenAnimation,
            Animation<double> secondaryAnimation) {
          return LeftDialog(parenAnimation, widget);
        });
  }

  static Future showCenterDialog(BuildContext context, Widget widget,
      {Function? onDispose}) {
    return showGeneralDialog(
        context: context,

        barrierDismissible: false,
        barrierColor: Color(0xa0000000),
        transitionDuration: Duration(milliseconds: 500),
        transitionBuilder: (ctx, a, b, w) {
          return w;
        },

        pageBuilder: (BuildContext context, Animation<double> parenAnimation,
            Animation<double> secondaryAnimation) {
          return CenterDialog(parenAnimation, widget, onDispose:onDispose,);
        });
  }
  static Future showToastDialog(BuildContext context, Widget widget,
      {Function? onDispose,Color? backgroundColor}) {
    return showGeneralDialog(
        context: context,

        barrierDismissible: false,
        barrierColor: backgroundColor??Color(0x80000000),
        transitionDuration: Duration(milliseconds: 600),
        transitionBuilder: (ctx, a, b, w) {
          return w;
        },

        pageBuilder: (BuildContext context, Animation<double> parenAnimation,
            Animation<double> secondaryAnimation) {
          return ToastDialog(parenAnimation, widget, onDispose:onDispose,backgroundColor: backgroundColor,);
        });
  }

  static Future showAffirmDialog(BuildContext context,
      {String title = "提示",
        String? message,
        String? leftButtonText,
        String rightButtonText="确定",
        VoidCallback? onLeftClick,
        VoidCallback? onDismissListener,
        Function? onDispose,
        List<TextSpan>? textSpan,
        Function? onBackgroundClick,
        Function? onRightClick}) async {
    assert(rightButtonText != null);
    await showCenterDialog(
        context,
        AffirmDialog(
          title: title,
          message: message,
          onLeftClick: onLeftClick,
          onRightClick: onRightClick as void Function()?,
          onBackgroundClick:onBackgroundClick as void Function()?,
          textLeftButton: leftButtonText,
          textSpan:textSpan,
          textRightButton: rightButtonText,
        ),onDispose: onDispose);
  }
}
